<template>
  <div class="clothing-history">
    <div class="page-header">
      <h1>中国服饰历史长卷</h1>
      <p class="subtitle">从远古到近代的服饰演变</p>
    </div>
    
    <div class="timeline">
      <div v-for="period in periods" :key="period.id" class="timeline-item">
        <div class="time-marker">
          <div class="year-label">{{ period.startYear }}</div>
          <div class="dot"></div>
        </div>
        
        <div class="period-content">
          <div class="period-header">
            <h2>{{ period.periodName }}</h2>
            <span class="year-range">{{ period.startYear }} - {{ period.endYear }}</span>
            <p class="period-desc">{{ period.description }}</p>
          </div>
          
          <div class="clothing-list">
            <el-card v-for="detail in periodDetails[period.id]" 
                    :key="detail.id" 
                    class="clothing-card"
                    :body-style="{ padding: '0px' }">
              <div class="card-content">
                <div class="image-wrapper" v-if="detail.imageUrl">
                  <el-image 
                    :src="detail.imageUrl"
                    fit="cover"
                    :preview-src-list="[detail.imageUrl]">
                  </el-image>
                </div>
                
                <div class="text-content">
                  <h3>{{ detail.clothingName }}</h3>
                  <div class="paragraphs">
                    <p v-for="(paragraph, index) in detail.description.split('[SPLIT]')" 
                       :key="index" 
                       class="paragraph">
                      {{ paragraph }}
                    </p>
                  </div>
                  
                  <div class="features-section">
                    <h4>特点</h4>
                    <p>{{ detail.features }}</p>
                  </div>
                  
                  <div class="meaning-section">
                    <h4>社会意义</h4>
                    <p>{{ detail.socialMeaning }}</p>
                  </div>
                </div>
              </div>
            </el-card>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getRequest } from '@/utils/request'
import { ElLoading } from 'element-plus'

const periods = ref([])
const periodDetails = ref({})

const loadData = async () => {
  const loading = ElLoading.service({
    lock: true,
    text: '加载历史数据中...',
    background: 'rgba(255, 255, 255, 0.7)'
  })
  
  try {
    // 获取所有历史时期
    const periodsRes = await getRequest('/api/clothing/history/period/list')
    periods.value = periodsRes.data

    // 获取每个时期的服饰详情
    for (const period of periods.value) {
      const detailsRes = await getRequest('/api/clothing/history/period/detail', {
        id: period.id
      })
      periodDetails.value[period.id] = detailsRes.data
    }
  } catch (error) {
    console.error('加载数据失败:', error)
  } finally {
    loading.close()
  }
}

onMounted(() => {
  loadData()
})
</script>

<style scoped>
.clothing-history {
  padding: 40px;
  max-width: 1200px;
  margin: 0 auto;
  background: #fff;
}

.page-header {
  text-align: center;
  margin-bottom: 60px;
}

.page-header h1 {
  font-size: 36px;
  color: #2c3e50;
  margin-bottom: 10px;
}

.subtitle {
  color: #7f8c8d;
  font-size: 18px;
}

.timeline {
  position: relative;
  padding: 40px 0;
}

.timeline::before {
  content: '';
  position: absolute;
  top: 0;
  left: 100px;
  height: 100%;
  width: 2px;
  background: linear-gradient(180deg, #e74c3c 0%, #3498db 100%);
}

.timeline-item {
  display: flex;
  margin-bottom: 60px;
  position: relative;
}

.time-marker {
  width: 200px;
  position: relative;
  padding-right: 40px;
  text-align: right;
}

.year-label {
  font-size: 20px;
  color: #34495e;
  font-weight: bold;
}

.dot {
  position: absolute;
  right: -6px;
  top: 50%;
  width: 12px;
  height: 12px;
  background: #3498db;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.2);
}

.period-content {
  flex: 1;
  padding-left: 40px;
}

.period-header {
  margin-bottom: 30px;
}

.period-header h2 {
  font-size: 28px;
  color: #2c3e50;
  margin-bottom: 10px;
}

.year-range {
  color: #7f8c8d;
  font-size: 16px;
}

.period-desc {
  color: #34495e;
  line-height: 1.6;
  margin-top: 10px;
}

.clothing-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 30px;
}

.clothing-card {
  transition: transform 0.3s ease;
}

.clothing-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
}

.card-content {
  padding: 20px;
}

.image-wrapper {
  height: 200px;
  overflow: hidden;
  border-radius: 8px;
  margin-bottom: 20px;
}

.text-content h3 {
  font-size: 20px;
  color: #2c3e50;
  margin-bottom: 15px;
}

.paragraphs {
  margin-bottom: 20px;
}

.paragraph {
  text-indent: 2em;
  line-height: 1.8;
  margin-bottom: 15px;
  color: #34495e;
}

.features-section,
.meaning-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.features-section h4,
.meaning-section h4 {
  color: #2c3e50;
  margin-bottom: 10px;
  font-size: 16px;
}

.features-section p,
.meaning-section p {
  color: #34495e;
  line-height: 1.6;
}
</style> 